<?php
	$options_jenis_test = array('' => "Select Test");
	foreach ($jenis_test as $row)
	{
        $options_jenis_test[$row['id']] = $row['name'];
	}
	
	$options_error_digit = array('' => "Error");
	for($i=1; $i<=10; $i++)
	{
        $options_error_digit[$i] = $i;
	}
?>

<script>
	<?php echo "var jumlah	 = ".$jml.";\n"; ?>
	<?php echo "var jenis	 = ".$jenis_test_selected.";\n"; ?>
</script>

<div id="page-wrapper">
	<div class="row">
		<div class="col-lg-12">
			<h1><i class="glyphicon glyphicon-edit"></i> Penilaian <small>(Penilaian Jawaban secara Otomatis)</small></h1>
			<ol class="breadcrumb">
				<li><a href="<?php echo base_url(); ?>admin"><i class="glyphicon glyphicon-home"></i> Dashboard</a></li>
				<li class="active"><i class="glyphicon glyphicon-edit"></i> Penilaian ({elapsed_time})</li>
			</ol>
		</div>
	</div><!-- /.row -->
	
	<div class="row">
		<div class="col-lg-12">
			<form action="<?php echo base_url(); ?>admin/penilaian/<?php echo$jenis_test_selected; ?>" method="post" name="form_penilaian" id="form_penilaian">
			<div class="form-actions">
			<p><h4>Pilih jenis test</h4></p>
			<?php
				echo validation_errors();
				echo '<div class="col-lg-2">';
				echo form_dropdown('id_jenis_test', $options_jenis_test, $jenis_test_selected, 'class="form-control" style="width:175px" onchange="drop_jenis_test(this.value)" data-toggle="tooltip" data-placement="bottom" title="Jenis Test"');
				echo '</div>';
			$options_method = array('' => 'Select Algoritm', 'tfidf' => 'TF-IDF', 'bleu' => 'BLEU');
			if($jenis_test_selected!=0){
				echo '<div class="col-lg-2">';
				echo form_dropdown('method', $options_method, $method_selected, 'class="form-control" style="width:175px" onchange="this.form.submit()" data-toggle="tooltip" data-placement="bottom" title="Algorithm"');
				echo '</div>';
				echo '<div class="col-lg-6">';
				echo form_dropdown('error_digit', $options_error_digit, $error_selected, 'class="form-control" style="width:83px" onchange="this.form.submit()" data-toggle="tooltip" data-placement="bottom" title="Error Digit"');
				echo '</div>';
				/*echo '<div class="col-lg-5">';
				echo '<div class="form-control" style="width:100px" data-toggle="tooltip" data-placement="bottom" title="Sinonim"><label class="checkbox-inline"><input name="sinonim" type="checkbox" onclick="this.form.submit()"> sinonim</label></div>';
				echo '</div>';*/
				echo '<div class="col-lg-1">';
				$data_submit = array('name' => 'hitung_submit', 'class' => 'btn btn-primary', 'value' => 'Hitung', 'style' => 'width:165px');
				echo form_submit($data_submit);
				echo '</div>';
			}
			?>
			</div>
			<br>
			<br>
			<?php
			if(isset($data)){
			?>
			<div class="table-responsive">
			<table class="table table-bordered table-hover table-striped tablesorter">
				<thead>
                  <tr>
                    <th>No</th>
                    <th width="18%">Soal <i class="glyphicon glyphicon-sort"></i></th>
                    <th width="35%">Kunci</i></th>
                    <th width="35%">Jawaban</th>
                    <td><input id="all" name="all" type="checkbox" onclick="check_2()"> Check</td>
                  </tr>
				</thead>
				<tbody>
				  <?php
				  $no = 1;
				  foreach($data as $row){
				  ?>
				  <tr id="tr<?php echo$no; ?>">
					<td><?php echo$no; ?><input type="hidden" value="<?php echo$no; ?>" name="no[<?php echo$row['id']; ?>]"></td>
					<td><?php echo$row['soal']; ?></td>
					<td>
					<?php
						$no_kunci = 1;
						foreach($kunci[$row['id']] as $id_kunci)
						{
							echo '<i class="glyphicon glyphicon-file"></i> <b>'.$no_kunci.'=></b> '.$id_kunci['kunci'].' ('.$id_kunci['skor'].')<br><br>';
							$no_kunci++;
						}
					?>
					</td>
					<td>
					<?php
						$no_jawaban = 1;
						foreach($jawaban[$row['id']] as $id_jawaban)
						{
							echo '<i class="glyphicon glyphicon-user"></i> <b>'.$id_jawaban['id_user'].'=></b> '.$id_jawaban['jawaban'];
							if($skor[$row['id']]!=null){
								echo ' <font color="red"><b>Skor = </b>';
								echo $skor[$row['id']]['nilai']['nilai'][$id_jawaban['id_user']];
								echo '</font>';
							}
							echo '<br><br>';
							$no_jawaban++;
						}
					?>
					</td>
					<td><input onclick="check()" type="checkbox" id="soal<?php echo$no; ?>" name="check[<?php echo$row['id']; ?>]" value="<?php echo$row['id']; ?>"></td>
				  </tr>
				  <?php
				  $no++;
				  }
				  ?>
				</tbody>
			</table>
			</div>
			<?php } ?>
			</form>
		</div>
	</div><!-- /.row -->
</div>

<script>
	function drop_jenis_test(jenis){
		window.location.assign("/CI_ku/admin/penilaian/"+jenis);
	}
	
	function check_2(){
		for(i=1;i<=jumlah;i++){
			if(document.getElementById('all').checked){
				document.getElementById('soal'+i).checked = true;
				document.getElementById('tr'+i).setAttribute("class", "success");
			}else{
				document.getElementById('soal'+i).checked = false;
				document.getElementById('tr'+i).setAttribute("class", "");
			}
		}
	}
	
	function check(){
		for(i=1;i<=jumlah;i++){
			if(document.getElementById('soal'+i).checked){
				document.getElementById('tr'+i).setAttribute("class", "success");
			}else {
				document.getElementById('tr'+i).setAttribute("class", "");
				document.getElementById('all').checked = false;
			}
		}
	}
</script>

<?php
if(isset($check)){
	foreach($check as $id){
		?>
		<script>
		var i = <?php echo $id ?>;
		document.getElementById('soal'+i).checked = true;
		document.getElementById('tr'+i).setAttribute("class", "success");
		</script>
		<?php
	}
	if(isset($check['all'])){
		?>
		<script>
		document.getElementById('all').checked = true;
		</script>
		<?php
	}
}
?>